#!/usr/bin/env python

import serial, time
#import datetime
#datetime.datetime.now().time()

s= serial.Serial()
s.baudrate = 9600
s.timeout = 0
s.port = "/dev/ttyAMA0"

try:
    s.open()
except serial.SerialException, e:
    sys.stderr.write("could not open port &r: %s\n" % (port, e))
    sys.exit(1)

s.write("$$$ALL,OFF\r")
time.sleep(2.5)
while True:
    for x in range (1,15):
       for y in range (1,10):
          if (x == 1) or (y == 1) or (x == 14 and y < 6):
                s.write("$$$P%d,%d,TOGGLE\r" %(x,y))
                time.sleep(0.1)
    time.sleep(1)
    for x in range (10,14):
        for y in range (4,9):
           if ((x == 10 or x == 12) and (y > 4 and y < 8)) or ((x == 11) and (y
== 4 or y == 8)) or (x == 13 and y == 6):
                s.write("$$$P%d,%d,TOGGLE\r" %(x,y))
                time.sleep(0.1)
    time.sleep(1)
    for x in range (6,10):
        y = 6
        s.write("$$$P%d,%d,TOGGLE\r" %(x,y))
        time.sleep(0.1)
    time.sleep(1)
    for y in range (7,10):
        x = 8
        s.write("$$$P%d,%d,TOGGLE\r" %(x,y))
        time.sleep(0.1)
    time.sleep(1)
    for y in range (3,6):
        x = 8
        s.write("$$$P%d,%d,TOGGLE\r" %(x,y))
        time.sleep(0.1)
    time.sleep(1)
    for x in range (3,6):
        for y in range (7,10):
           if (x == 3 and y == 9) or (x == 4 and y == 8) or (x == 5 and y ==7):
                s.write("$$$P%d,%d,TOGGLE\r" %(x,y))
                time.sleep(0.1)
    time.sleep(1)
    for x in range (3,6):
        for y in range (3,6):
           if (x == y):
                s.write("$$$P%d,%d,TOGGLE\r" %(x,y))
                time.sleep(0.1)

    time.sleep(3)
    s.write("$$$ALL,OFF\r")
